#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int n;
	while(scanf("%d",&n)&&n!=0)
	{
		//printf("*******\n");
		char mp[n+2][n+2];
		int num[10]={0};
		for(int i = 0;i<3;i++)
		{
			for(int j = 0;j<n;j++)
			{
				cin>>mp[i][j];
			}
		}
		for(int j = 0;j<n;j++)
		{
			int tmp = 10;
			for(int i = 0;i<3;i++)
			{
				tmp = min(tmp,(mp[i][j]-'A'));
			}
			num[tmp]++;
			printf("%c",'A'+tmp);
		}	
		printf("\n");
		printf("%d",num[0]);
		for(int i = 1;i<5;i++) printf(" %d",num[i]);
		printf("\n"); 
	}
}
